<template>
  <div class='add-directory'>
    <el-dialog :title="title.text+title.pageTitle" :visible.sync="dialogFormVisible" width="28%">
      <el-form ref="form" :model="changeForm" :rules="rules" size="mini" style="text-align:center">
        <el-form-item label="所属学科" style="margin-left:10px" v-show="!flagID">
          <el-select v-model="changeForm.subjectID" placeholder="请选择" style="width:230px">
            <el-option
              v-for="item in subject"
              :key="item.value"
              :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="目录名称" prop="directoryName">
          <el-input v-model="changeForm.directoryName"  placeholder="请输入目录名称" style="width:230px"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" style="text-align:right">
        <el-button @click="dialogFormVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="hSure" size="mini">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 导入学科列表接口
import { simple } from '@/api/hmmm/subjects.js'
export default {
  name: 'add-dialog',
  props: ['title', 'changeForm', 'flagID'],
  data () {
    return {
      dialogFormVisible: false,
      // 频道列表
      subject: [],
      rules: {
        subject: [
          { required: true, message: '请选择所属学科', trigger: 'change' }
        ],
        directoryName: [
          { required: true, message: '请输入目录名称', trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    this.getChannels()
  },
  methods: {
    // 获取学科列表
    async getChannels () {
      const result = await simple()
      this.subject = result.data
    },
    // 弹层显示
    dialogFormV () {
      this.dialogFormVisible = true
    },
    // 弹层隐藏
    dialogFormH () {
      this.dialogFormVisible = false
    },
    // 点击确定按钮
    hSure () {
      this.$emit('addData', this.changeForm, this.title.text)
    }
  }
}
</script>

<style scoped lang='less'></style>
